/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ExamingPanel.java
 *
 * Created on 2012-6-4, 22:38:12
 */
package icexam.exam;

import icexam.ICExamView;
import icexam.exam.print.ReportViewAction;
import java.awt.Color;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.border.LineBorder;

/**
 *
 * @author Ethan
 */
public class ExamingPanel extends javax.swing.JPanel {

    private JLabel[] lableIndexs;
    /** Creates new form ExamingPanel */
    long startTime = -1;
    private ICExamView mainView;
    private boolean testOver;

    ExamingPanel(ICExamView mainView, List<Issue> qs) {
        this(mainView);
        this.qs = qs;
        loaderQ();
//        startTime = System.currentTimeMillis();
        startTime();
    }

    public boolean isTestOver() {
        return testOver;
    }

    public void setTestOver(boolean testOver) {
        this.testOver = testOver;
    }
    public ExamingPanel(ICExamView aThis) {
        initComponents();
        this.mainView = aThis;
        this.mainView.studying();
        reP.setVisible(false);
        qTitleTxt.setEditable(false);
        buttonGroup1.add(aSel);
        buttonGroup1.add(bSel);
        
        solutionP.setVisible(false);
//        loaderQ();
        qTitleTxt.setLineWrap(true);
        qTitleTxt.setWrapStyleWord(true);

//        jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
//            public void mouseClicked(java.awt.event.MouseEvent evt) {
//                jLabel1MouseClicked(evt);
//            }
//        });
//        jLabel22.addMouseListener(new java.awt.event.MouseAdapter() {
//            public void mouseClicked(java.awt.event.MouseEvent evt) {
//                jLabel1MouseClicked(evt);
//            }
//        });
//        jLabel33.addMouseListener(new java.awt.event.MouseAdapter() {
//            public void mouseClicked(java.awt.event.MouseEvent evt) {
//                jLabel1MouseClicked(evt);
//            }
//        });

        lableIndexs = new JLabel[50];
        for(int i=0;i<lableIndexs.length;i++){
            lableIndexs[i] = new JLabel();
            lableIndexs[i].setOpaque(true);
            lableIndexs[i].setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
            lableIndexs[i].setText(String.valueOf(i+1)); // NOI18N
//            javax.swing.border.LineBorder();
            lableIndexs[i].setBorder(new LineBorder(new Color(102, 102, 255), 1, true)); // NOI18N
            lableIndexs[i].setName("jLabel1"); // NOI18N
            lableIndexs[i].addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    goToCurrQ(evt);
//                    jLabel1MouseClicked(evt);
                }
            });
            indexsP.add(lableIndexs[i]);
        }

    }

    private int qIndex = -1;
    private List<Issue> qs = null;
    public void loaderQ(){
        
        qIndex = 0;
        indexT.setText(String.valueOf(qIndex+1));
        Issue q = qs.get(qIndex);
        fillQ(q);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel2 = new javax.swing.JPanel();
        exP = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        questionsT = new javax.swing.JLabel();
        indexT = new javax.swing.JLabel();
        questionsT1 = new javax.swing.JLabel();
        qTitleTxt = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        aP = new javax.swing.JPanel();
        aSel = new javax.swing.JRadioButton();
        bP = new javax.swing.JPanel();
        bSel = new javax.swing.JRadioButton();
        reP = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        fractionT = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        successP = new javax.swing.JPanel();
        passT = new javax.swing.JLabel();
        checkWhatsWrongB1 = new javax.swing.JButton();
        checkWhatsWrongB2 = new javax.swing.JButton();
        gameOverP = new javax.swing.JPanel();
        gameOverT = new javax.swing.JLabel();
        checkWhatsWrongB = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        ctrlP = new javax.swing.JPanel();
        jLabel51 = new javax.swing.JLabel();
        myAnsT = new javax.swing.JLabel();
        pButton = new javax.swing.JButton();
        nButton = new javax.swing.JButton();
        nButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        timeCutT = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        indexsP = new javax.swing.JPanel();
        solutionP = new javax.swing.JPanel();
        wrightAnsT = new javax.swing.JLabel();
        wrightAnsT1 = new javax.swing.JLabel();

        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(600, 720));

        jPanel2.setMinimumSize(new java.awt.Dimension(559, 25));
        jPanel2.setName("jPanel2"); // NOI18N
        jPanel2.setPreferredSize(new java.awt.Dimension(589, 470));

        exP.setName("exP"); // NOI18N
        exP.setPreferredSize(new java.awt.Dimension(589, 210));
        exP.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));

        jPanel9.setName("jPanel9"); // NOI18N
        jPanel9.setPreferredSize(new java.awt.Dimension(580, 25));
        jPanel9.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 1));

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(icexam.ICExamApp.class).getContext().getResourceMap(ExamingPanel.class);
        questionsT.setFont(resourceMap.getFont("questionsT1.font")); // NOI18N
        questionsT.setText(resourceMap.getString("questionsT.text")); // NOI18N
        questionsT.setName("questionsT"); // NOI18N
        questionsT.setPreferredSize(new java.awt.Dimension(20, 22));
        jPanel9.add(questionsT);

        indexT.setFont(resourceMap.getFont("questionsT1.font")); // NOI18N
        indexT.setText(resourceMap.getString("indexT.text")); // NOI18N
        indexT.setName("indexT"); // NOI18N
        indexT.setPreferredSize(new java.awt.Dimension(15, 15));
        jPanel9.add(indexT);

        questionsT1.setFont(resourceMap.getFont("questionsT1.font")); // NOI18N
        questionsT1.setText(resourceMap.getString("questionsT1.text")); // NOI18N
        questionsT1.setName("questionsT1"); // NOI18N
        questionsT1.setPreferredSize(new java.awt.Dimension(20, 22));
        jPanel9.add(questionsT1);

        exP.add(jPanel9);

        qTitleTxt.setBackground(resourceMap.getColor("qTitleTxt.background")); // NOI18N
        qTitleTxt.setColumns(20);
        qTitleTxt.setFont(resourceMap.getFont("qTitleTxt.font")); // NOI18N
        qTitleTxt.setLineWrap(true);
        qTitleTxt.setRows(5);
        qTitleTxt.setTabSize(0);
        qTitleTxt.setText(resourceMap.getString("qTitleTxt.text")); // NOI18N
        qTitleTxt.setMinimumSize(new java.awt.Dimension(580, 22));
        qTitleTxt.setName("qTitleTxt"); // NOI18N
        qTitleTxt.setPreferredSize(new java.awt.Dimension(580, 100));
        exP.add(qTitleTxt);

        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setPreferredSize(new java.awt.Dimension(580, 80));

        aP.setName("aP"); // NOI18N
        aP.setPreferredSize(new java.awt.Dimension(550, 25));
        aP.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        aSel.setFont(resourceMap.getFont("aSel.font")); // NOI18N
        aSel.setText(resourceMap.getString("aSel.text")); // NOI18N
        aSel.setName("aSel"); // NOI18N
        aSel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aSelActionPerformed(evt);
            }
        });
        aP.add(aSel);

        jPanel3.add(aP);

        bP.setName("bP"); // NOI18N
        bP.setPreferredSize(new java.awt.Dimension(550, 25));
        bP.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        bSel.setFont(resourceMap.getFont("aSel.font")); // NOI18N
        bSel.setText(resourceMap.getString("bSel.text")); // NOI18N
        bSel.setName("bSel"); // NOI18N
        bSel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bSelActionPerformed(evt);
            }
        });
        bP.add(bSel);

        jPanel3.add(bP);

        exP.add(jPanel3);

        jPanel2.add(exP);

        reP.setName("reP"); // NOI18N
        reP.setPreferredSize(new java.awt.Dimension(589, 260));

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setPreferredSize(new java.awt.Dimension(580, 60));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 580, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 60, Short.MAX_VALUE)
        );

        reP.add(jPanel1);

        jPanel4.setName("jPanel4"); // NOI18N
        jPanel4.setPreferredSize(new java.awt.Dimension(580, 35));

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        jLabel1.setPreferredSize(new java.awt.Dimension(84, 15));
        jPanel4.add(jLabel1);

        fractionT.setFont(resourceMap.getFont("fractionT.font")); // NOI18N
        fractionT.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        fractionT.setText(resourceMap.getString("fractionT.text")); // NOI18N
        fractionT.setName("fractionT"); // NOI18N
        fractionT.setPreferredSize(new java.awt.Dimension(40, 27));
        jPanel4.add(fractionT);

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N
        jLabel3.setPreferredSize(new java.awt.Dimension(40, 15));
        jPanel4.add(jLabel3);

        reP.add(jPanel4);

        jPanel6.setName("jPanel6"); // NOI18N
        jPanel6.setPreferredSize(new java.awt.Dimension(580, 35));

        successP.setName("successP"); // NOI18N
        successP.setPreferredSize(new java.awt.Dimension(400, 25));
        successP.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        passT.setText(resourceMap.getString("passT.text")); // NOI18N
        passT.setName("passT"); // NOI18N
        passT.setPreferredSize(new java.awt.Dimension(135, 25));
        successP.add(passT);

        checkWhatsWrongB1.setText(resourceMap.getString("checkWhatsWrongB1.text")); // NOI18N
        checkWhatsWrongB1.setName("checkWhatsWrongB1"); // NOI18N
        checkWhatsWrongB1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkWhatsWrongB1ActionPerformed(evt);
            }
        });
        successP.add(checkWhatsWrongB1);

        checkWhatsWrongB2.setText(resourceMap.getString("checkWhatsWrongB2.text")); // NOI18N
        checkWhatsWrongB2.setName("checkWhatsWrongB2"); // NOI18N
        checkWhatsWrongB2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkWhatsWrongB2ActionPerformed(evt);
            }
        });
        successP.add(checkWhatsWrongB2);

        jPanel6.add(successP);

        gameOverP.setName("gameOverP"); // NOI18N
        gameOverP.setPreferredSize(new java.awt.Dimension(400, 25));
        gameOverP.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        gameOverT.setText(resourceMap.getString("gameOverT.text")); // NOI18N
        gameOverT.setName("gameOverT"); // NOI18N
        gameOverT.setPreferredSize(new java.awt.Dimension(252, 23));
        gameOverP.add(gameOverT);

        checkWhatsWrongB.setText(resourceMap.getString("checkWhatsWrongB.text")); // NOI18N
        checkWhatsWrongB.setName("checkWhatsWrongB"); // NOI18N
        checkWhatsWrongB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkWhatsWrongBActionPerformed(evt);
            }
        });
        gameOverP.add(checkWhatsWrongB);

        jPanel6.add(gameOverP);

        reP.add(jPanel6);

        jPanel2.add(reP);

        jSeparator1.setName("jSeparator1"); // NOI18N
        jSeparator1.setPreferredSize(new java.awt.Dimension(589, 5));
        jPanel2.add(jSeparator1);

        ctrlP.setName("ctrlP"); // NOI18N
        ctrlP.setPreferredSize(new java.awt.Dimension(580, 30));
        ctrlP.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jLabel51.setFont(resourceMap.getFont("aSel.font")); // NOI18N
        jLabel51.setText(resourceMap.getString("jLabel51.text")); // NOI18N
        jLabel51.setName("jLabel51"); // NOI18N
        ctrlP.add(jLabel51);

        myAnsT.setText(resourceMap.getString("myAnsT.text")); // NOI18N
        myAnsT.setName("myAnsT"); // NOI18N
        myAnsT.setPreferredSize(new java.awt.Dimension(120, 22));
        ctrlP.add(myAnsT);

        pButton.setFont(resourceMap.getFont("aSel.font")); // NOI18N
        pButton.setText(resourceMap.getString("pButton.text")); // NOI18N
        pButton.setName("pButton"); // NOI18N
        pButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pButtonActionPerformed(evt);
            }
        });
        ctrlP.add(pButton);

        nButton.setFont(resourceMap.getFont("aSel.font")); // NOI18N
        nButton.setText(resourceMap.getString("nButton.text")); // NOI18N
        nButton.setName("nButton"); // NOI18N
        nButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nButtonActionPerformed(evt);
            }
        });
        ctrlP.add(nButton);

        nButton1.setFont(resourceMap.getFont("nButton1.font")); // NOI18N
        nButton1.setText(resourceMap.getString("nButton1.text")); // NOI18N
        nButton1.setName("nButton1"); // NOI18N
        nButton1.setPreferredSize(new java.awt.Dimension(57, 25));
        nButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nButton1ActionPerformed(evt);
            }
        });
        ctrlP.add(nButton1);

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setMaximumSize(new java.awt.Dimension(64, 15));
        jLabel2.setName("jLabel2"); // NOI18N
        jLabel2.setPreferredSize(new java.awt.Dimension(100, 15));
        ctrlP.add(jLabel2);

        timeCutT.setFont(resourceMap.getFont("timeCutT.font")); // NOI18N
        timeCutT.setForeground(resourceMap.getColor("timeCutT.foreground")); // NOI18N
        timeCutT.setText(resourceMap.getString("timeCutT.text")); // NOI18N
        timeCutT.setName("timeCutT"); // NOI18N
        timeCutT.setPreferredSize(new java.awt.Dimension(22, 22));
        ctrlP.add(timeCutT);

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N
        ctrlP.add(jLabel4);

        jPanel2.add(ctrlP);

        indexsP.setName("indexsP"); // NOI18N
        indexsP.setPreferredSize(new java.awt.Dimension(400, 160));
        indexsP.setLayout(new java.awt.GridLayout(5, 10, 5, 5));
        jPanel2.add(indexsP);

        solutionP.setName("solutionP"); // NOI18N
        solutionP.setPreferredSize(new java.awt.Dimension(580, 30));

        wrightAnsT.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        wrightAnsT.setText(resourceMap.getString("wrightAnsT.text")); // NOI18N
        wrightAnsT.setName("wrightAnsT"); // NOI18N
        wrightAnsT.setPreferredSize(new java.awt.Dimension(120, 25));
        solutionP.add(wrightAnsT);

        wrightAnsT1.setFont(resourceMap.getFont("wrightAnsT1.font")); // NOI18N
        wrightAnsT1.setForeground(resourceMap.getColor("wrightAnsT1.foreground")); // NOI18N
        wrightAnsT1.setName("wrightAnsT1"); // NOI18N
        wrightAnsT1.setPreferredSize(new java.awt.Dimension(42, 25));
        solutionP.add(wrightAnsT1);

        jPanel2.add(solutionP);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 544, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(176, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    private void goToPrefQ(){
        if(qIndex>0){
            qIndex--;
            Issue q = qs.get(qIndex);
            if(q.getUserSelIndex()!=-1){
                switch(q.getUserSelIndex()){
                    case 0: aSel.setSelected(true);break;
                    case 1: bSel.setSelected(true);break;
                }
            }else{
//                myAnsT.setText("");
                buttonGroup1.clearSelection();
            }
            indexT.setText(String.valueOf(qIndex+1));
            fillQ(q);
        }
    }
    private void goToNextQ(){
        if(qs.get(qIndex).getUserSelIndex()!=-1)
                lableIndexs[this.qIndex].setBackground(Color.GREEN);
        if(qIndex<50-1){
            //???????????????????????????????????????????????????????????????
            
            qIndex++;
            Issue q = qs.get(qIndex);
            if(q.getUserSelIndex()!=-1){
                switch(q.getUserSelIndex()){
                    case 0: aSel.setSelected(true);break;
                    case 1: bSel.setSelected(true);break;
                }
            }else{
//                myAnsT.setText("");
                buttonGroup1.clearSelection();
            }
            indexT.setText(String.valueOf(qIndex+1));
            fillQ(q);
        }
    }
    private void aSelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aSelActionPerformed
        currentQ.setUserSelIndex(0);
        myAnsT.setText(A);
        timer.schedule(new TimerTask(){
        public void run(){
        goToNextQ();
        this.cancel();}},100);
    }//GEN-LAST:event_aSelActionPerformed
    Timer timer = new Timer();
   
    private void bSelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSelActionPerformed
        currentQ.setUserSelIndex(1);
        myAnsT.setText(B);
        timer.schedule(new TimerTask(){
        public void run(){
        goToNextQ();
        this.cancel();}},100);
        
    }//GEN-LAST:event_bSelActionPerformed

    private void nButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nButton1ActionPerformed
        getResult();
        
    }//GEN-LAST:event_nButton1ActionPerformed

    private void checkWhatsWrongBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkWhatsWrongBActionPerformed
        exP.setVisible(true);
        this.reP.setVisible(false);
        this.indexsP.setVisible(true);
        
        changeIndexWrong();
    }//GEN-LAST:event_checkWhatsWrongBActionPerformed

    private void nButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nButtonActionPerformed
        goToNextQ();
}//GEN-LAST:event_nButtonActionPerformed

    private void pButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pButtonActionPerformed
        goToPrefQ();
}//GEN-LAST:event_pButtonActionPerformed

    private void checkWhatsWrongB1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkWhatsWrongB1ActionPerformed
        try {
//            logger.info("Start preview report.");
            String[][] titles = new String[3][6];
            String[][] objs = new String[50][6];
            titles[0][0] = "字号名称："+this.mainView.getUser().getCompName()
                    + "   负责人 ： "
                    + this.mainView.getUser().getCeoName();
            titles[0][1] = "容县流通环节食品安全知识测试题";
//            titles[0][1] = "身份证："
//                    + this.mainView.getUser().getIdcard();
            titles[0][2] = "成绩："+nowScore;

            titles[1][0] = "题号";
            titles[1][1] = "试题";
            titles[1][2] = "";
            titles[1][3] = "";
            titles[1][4] = "您的选择";
            titles[1][5] = "正确答案";
            System.out.println(objs.length);
            for(int i=0;i<qs.size();i++){
                objs[i][0] = String.valueOf(i+1);
                objs[i][1] = qs.get(i).getIssue();
                if(qs.get(i).getQuestionType()==0){
                    objs[i][2] = "A:"+qs.get(i).getAnswers()[0];
                    objs[i][3] = "B:"+qs.get(i).getAnswers()[1];
                }else{
                    objs[i][2] = "A: 正确";
                    objs[i][3] = "B: 错误";
                }
//                objs[i][2] = "A:"+qs.get(i).getAnswers()[0];
//                objs[i][3] = "B:"+qs.get(i).getAnswers()[1];
                if(qs.get(i).getUserSelIndex()<0){
                    objs[i][4] = " ";
                }else
                    objs[i][4] = (qs.get(i).getUserSelIndex()==0)?"A":"B";
                objs[i][5] = (qs.get(i).getStandardAnswerIndex()==0)?"A":"B";
            }
            ReportViewAction.action(titles, objs,1);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_checkWhatsWrongB1ActionPerformed

    private void checkWhatsWrongB2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkWhatsWrongB2ActionPerformed
        try {
            String[][] titles = new String[3][3];
            titles[0][0] = "合格证书";
             SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日");//设置日期格式
            titles[0][1] = "容县工商行政管理局 "
                    + df.format(new Date());
            String[][] objs = new String[1][3];
            objs[0][0] = "      "+this.mainView.getUser().getCeoName()
                    + " 参加我局举办的容县流通环节食品安全知识培训，并通过了测试，特发此证。";
            ReportViewAction.action(titles, objs,3);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_checkWhatsWrongB2ActionPerformed

    public void goToCurrQ(java.awt.event.MouseEvent evt){
        JLabel jl = (JLabel) evt.getSource();
        //        jl.getText()
        int index = Integer.valueOf(jl.getText());
        qIndex = index-1;
        Issue q = qs.get(qIndex);
        
        indexT.setText(String.valueOf(qIndex+1));
        fillQ(q);
        if(testOver){
            if(q.getUserSelIndex()!=q.getStandardAnswerIndex()){
                this.solutionP.setVisible(true);
                switch(q.getStandardAnswerIndex()){
                    case 0: wrightAnsT1.setText(A);break;
                    case 1: wrightAnsT1.setText(B);break;
                }

            }else{
                this.solutionP.setVisible(false);
            }
        }
        
        //        this.currentQ =
        System.out.println(jl.getText());
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel aP;
    private javax.swing.JRadioButton aSel;
    private javax.swing.JPanel bP;
    private javax.swing.JRadioButton bSel;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton checkWhatsWrongB;
    private javax.swing.JButton checkWhatsWrongB1;
    private javax.swing.JButton checkWhatsWrongB2;
    private javax.swing.JPanel ctrlP;
    private javax.swing.JPanel exP;
    private javax.swing.JLabel fractionT;
    private javax.swing.JPanel gameOverP;
    private javax.swing.JLabel gameOverT;
    private javax.swing.JLabel indexT;
    private javax.swing.JPanel indexsP;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel51;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel myAnsT;
    private javax.swing.JButton nButton;
    private javax.swing.JButton nButton1;
    private javax.swing.JButton pButton;
    private javax.swing.JLabel passT;
    private javax.swing.JTextArea qTitleTxt;
    private javax.swing.JLabel questionsT;
    private javax.swing.JLabel questionsT1;
    private javax.swing.JPanel reP;
    private javax.swing.JPanel solutionP;
    private javax.swing.JPanel successP;
    private javax.swing.JLabel timeCutT;
    private javax.swing.JLabel wrightAnsT;
    private javax.swing.JLabel wrightAnsT1;
    // End of variables declaration//GEN-END:variables

    private static final String TitleSpace = "   ";
    private static final String A = " A ";
    private static final String B = " B ";
    private static final String ASelKey = " A: ";
    private static final String BSelKey = " B: ";
    private static final String TrueSelKey = " 正确";
    private static final String FalseSelKey = " 错误";

    private Issue currentQ;
    private void fillQ(Issue q) {
        currentQ = q;
        qTitleTxt.setText(TitleSpace+q.getIssue());
        if(q.getQuestionType()==q.Questiong_Select){
            aSel.setText(ASelKey+ q.getAnswers()[0]);
            bSel.setText(BSelKey+ q.getAnswers()[1]);
        }else{
            aSel.setText(ASelKey+ TrueSelKey);
            bSel.setText(BSelKey+ FalseSelKey);
        }
        
        if(q.getUserSelIndex()!=-1){
            switch(q.getUserSelIndex()){
                case 0: aSel.setSelected(true);myAnsT.setText(A);break;
                case 1: bSel.setSelected(true);myAnsT.setText(B);break;
            }
            
        }else{
            buttonGroup1.clearSelection();
            myAnsT.setText("");
        }
        
    }

    private int nowScore = 0;
    private final static int LevelScore = 90;
    public void getResult() {

        this.testOver = true;
        nowScore = checkResult();
        aSel.setEnabled(false);
        bSel.setEnabled(false);
        fractionT.setText(String.valueOf(nowScore));
        if(nowScore>=LevelScore){
            fractionT.setForeground(Color.GREEN);
            successP.setVisible(true);
            gameOverP.setVisible(false);
        }else{
            fractionT.setForeground(Color.RED);
            successP.setVisible(false);
            gameOverP.setVisible(true);
        }
        mainView.setSubmitExam(nowScore);
        indexsP.setVisible(false);
        this.ctrlP.setVisible(false);
        this.exP.setVisible(false);
        this.reP.setVisible(true);
    }

    private int checkResult() {
        int value = 0;
        for(Issue q : qs){
            if(q.getStandardAnswerIndex()==q.getUserSelIndex()){
                value += 2;
            }
        }
        return value;
    }

    private void changeIndexWrong() {

        for(int i=0;i<qs.size();i++){
            Issue q = qs.get(i);
            if(q.getUserSelIndex()==q.getStandardAnswerIndex()){
                lableIndexs[i].setBackground(Color.GREEN);
            }else if(q.getUserSelIndex()==-1){
                lableIndexs[i].setBackground(Color.WHITE);
            }else
                lableIndexs[i].setBackground(Color.RED);
        }
        
    }

    private void startTime() {
        TimeTast myTimeTask = new TimeTast();
        startTime = System.currentTimeMillis();
        new Timer().schedule(myTimeTask, 3*1000, 60*1000);
    }



    class TimeTast extends TimerTask{

        public void run(){
             long newTime = System.currentTimeMillis();
             int spent = (int) ((newTime - startTime) / 60000);
             if(spent>60){
                 ExamingPanel.this.getResult();
             }else{
                 ExamingPanel.this.timeCutT.setText(String.valueOf(60-spent));
             }

        }
    }
}
